package cn.com.gridinfo.sooc.core.expand.callname.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.marshalchen.ultimaterecyclerview.UltimateRecyclerviewViewHolder;
import com.marshalchen.ultimaterecyclerview.UltimateViewAdapter;

import java.util.List;

import cn.com.gridinfo.sooc.R;
import cn.com.gridinfo.sooc.core.expand.callname.bean.Student;

/**
 * 签到详情的Fragment 应到 适配器
 *
 * @author yingchunli
 */
public class YingDaoAdapter extends UltimateViewAdapter<YingDaoAdapter.ViewHolder> {

    public List<Student> studentList;
    Context context;

    public YingDaoAdapter(List<Student> studentList, Context context) {
        this.studentList = studentList;
        this.context = context;
    }

    @Override
    public RecyclerView.ViewHolder onCreateHeaderViewHolder(ViewGroup parent) {
        return null;
    }

    @Override
    public void onBindHeaderViewHolder(RecyclerView.ViewHolder holder, int position) {

    }

    @Override
    public ViewHolder getViewHolder(View view) {
        return new ViewHolder(view, false);
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent) {
        //加载布局
        View view = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.expand_callname_signinfo_yingdao_item, parent, false);
        return new ViewHolder(view, true);
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        if (position < getItemCount() &&
                (customHeaderView != null ? position <= studentList.size() : position < studentList.size())
                && (customHeaderView != null ? position > 0 : true)) {
            Student student = studentList.get(position);
            holder.xmxh.setText(student.getXm() + "（" + student.getXh() + "）");
            holder.bj.setText(student.getBj());
            //底部分割线的显示
//            if (position == studentList.size() - 1) {
//                holder.line.setVisibility(View.VISIBLE);
//            } else {
//                holder.line.setVisibility(View.GONE);
//            }
        }
    }

    public void loadmore(List<Student> list) {
        studentList.addAll(list);
        notifyDataSetChanged();
    }

    public void refresh(List<Student> list) {
        studentList.clear();
        studentList.addAll(list);
        notifyDataSetChanged();
    }

    @Override
    public int getAdapterItemCount() {
        return studentList.size();
    }

    @Override
    public long generateHeaderId(int position) {
        return position;
    }

    //ViewHolder
    public class ViewHolder extends UltimateRecyclerviewViewHolder {
        TextView xmxh, bj;
        View line;

        public ViewHolder(View itemView, boolean isItem) {
            super(itemView);
            if (isItem) {
                xmxh = (TextView) itemView.findViewById(R.id.xmxh_yingdao);
                bj = (TextView) itemView.findViewById(R.id.bj_yingdao);
//                line =  itemView.findViewById(R.id.line_bottom);//底部分割线
            }
        }
    }
}
